function Collect_mixed_FEdemoshrt_grID_wtp_tomlab_varagin_j_bs(subsample,inc,set_seed,matlab_seed,get_nb_draws)

%matlab_seed=1353;
rng(matlab_seed)

	tmp_file1=strcat('\\c3\rdat\SHoude\Research/sears/estar_data\refrigerators\choiceset_identifier_trimester_week_zipcode_2008_2012_v11022017_struct_',num2str(subsample),'_',num2str(inc),'_seed_',num2str(set_seed),'.csv');
    id=load(tmp_file1); 
	Nmax=size(id,1);
	if subsample == 11000
		bs_max=10*ceil(Nmax/10000);
    elseif subsample == 44000
		%bs_max=10*ceil(Nmax/20000); 
         bs_max = 16;
    end

for j=1:bs_max	
    
    if subsample == 11000
		index_bs=[(1+(j-1)*(1000)):min(j*(1000),Nmax)];
    elseif subsample == 44000
		index_bs=[(1+(j-1)*(2000)):min(j*(2000),Nmax)];
	end
    
    tmp_file1=strcat('\\c3\rdat\SHoude\Research/sears/estar_data\refrigerators\choiceset_identifier_trimester_week_zipcode_2008_2012_v11022017_struct_',num2str(subsample),'_',num2str(inc),'_seed_',num2str(set_seed),'.csv');
    id=load(tmp_file1);
    id=id(index_bs,:);
    id(:,1:7)=[];
    choicest_size=sum(id,2);
    %id_discard=find(choicest_size>200 | choicest_size<50);
    id_discard=find(choicest_size>400);
    id(id_discard,:)=[];  
    choicest_size(id_discard)=[]; 
    id=id';
    id_R=repmat(id,1,get_nb_draws);
    [id_i,id_j,id_s]=find(id_R);
    id_ij=find(id_R);
    [id_m,id_n] = size(id_R);
    
    MT=size(id,2);
    %MTvector=ones(MT,1);
    MTR=size(id_R,2);
    %MTRvector=ones(MTR,1);
    J=size(id,1);
    
	results_file=strcat('\\c3\rdat\SHoude\Research/sears/estar_results/struct_est/','mixed_logit_FEdemoshrt_grID_wtp_100iters_',num2str(subsample),'_',num2str(inc),'_',num2str(set_seed),'_matlab_seed_',num2str(matlab_seed),'_nb_draws_',num2str(get_nb_draws),'bs_',num2str(j),'.mat');
    mixed=load(results_file);
 
    eta(j)=mixed.theta_est1(J);
    tau(j)=mixed.theta_est1(J+1);
    pi(j)=mixed.theta_est1(J+2);
    theta(j)=mixed.theta_est1(J+3);
 	L11(j)=mixed.theta_est1(J+16);
    L21(j)=mixed.theta_est1(J+17);
    L22(j)=mixed.theta_est1(J+18);
 
 
end


colNames = {'eta','theta','L11','L21','L22','tau','pi'};
Table_beta = [eta',theta',L11',L21',L22',tau',pi'];
Table_beta_n = array2table(Table_beta,'VariableNames',colNames);
			
results_all=strcat('\\c3\rdat\SHoude\Research/sears/estar_results/struct_est/','mixed_logit_FEdemoshrt_grID_wtp_100iters_',num2str(subsample),'_',num2str(inc),'_',num2str(set_seed),'_matlab_seed_',num2str(matlab_seed),'_nb_draws_',num2str(get_nb_draws),'all_bs','.csv');
    
writetable(Table_beta_n,results_all);

%results_file_100=strcat('\\c3\rdat\SHoude\Research/sears/estar_results/struct_est/','mixed_logit_FEdemoshrt_grID_wtp_100iters_',num2str(subsample),'_',num2str(inc),'_',num2str(set_seed),'_matlab_seed_',num2str(matlab_seed),'_nb_draws_',num2str(get_nb_draws),'.mat');
%    mixed_100=load(results_file_100);
 
%     eta_mixed   = mixed_100.theta_est1(J);
%     tau_mixed   = mixed_100.theta_est1(J+1);
%     pi_mixed    = mixed_100.theta_est1(J+2);
%     theta_mixed = mixed_100.theta_est1(J+3);
%  	L11_mixed   = mixed_100.theta_est1(J+16);
%     L21_mixed   = mixed_100.theta_est1(J+17);
%     L22_mixed   = mixed_100.theta_est1(J+18);
 
results_file_clogit=strcat('\\c3\rdat\SHoude\Research/sears/estar_results/struct_est/','hom_FEdemoshrt_wtp_LLC_5_18',num2str(subsample),'_inc',num2str(inc),'_sd',num2str(set_seed),'_04132018.mat');    
    clogit=load(results_file_clogit);
    eta_clogit=clogit.theta_est1(J);
    tau_clogit=clogit.theta_est1(J+1);
    pi_clogit=clogit.theta_est1(J+2);
    theta_clogit=clogit.theta_est1(J+3);
 	    
%Table_beta_mixed  = [eta_mixed', theta_mixed', L11_mixed', L21_mixed', L22_mixed', tau_mixed', pi_mixed'];
Table_beta_clogit = [eta_clogit, theta_clogit, tau_clogit, pi_clogit]; 

end

